package com.heima.admin.job;

import com.heima.admin.service.WemediaNewsAutoScanService;
import com.heima.feigns.WemediaFeign;
import com.heima.model.common.dtos.ResponseResult;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class WeMediaNewsAutoScanJob {
    //定时扫描待发布文章
    //定时任务结果
    @Autowired
    private WemediaFeign wemediaFeign;
    @Autowired
    private WemediaNewsAutoScanService wemediaNewsAutoScanService;
@XxlJob("weMediaAutoScanJob")
    public ReturnT weMediaNewsAutoScanJob(String Params) {
    log.info("定时发布任务被触发  start==========================>");
    //远程调用findRelease()方法
    ResponseResult<List<Integer>> release = wemediaFeign.findRelease();
    //判断
    if (release.getCode().intValue() != 0) {
        //返回错误信息
        log.error("远程调用出错====》，原因：{}", release.getErrorMessage());
        //返回结果
        return ReturnT.FAIL;
    }


    //release.getData()得到集合
    List<Integer> releaseList = release.getData();
    //遍历集合
    for (Integer id : releaseList) {
        wemediaNewsAutoScanService.autoScanByMediaNewsId(id);
    }
    log.info("自媒体文章审核调度任务结束========>");
    return ReturnT.SUCCESS;
    }




}
